package com.tarena.lbs.activity.service.impl;

import com.tarena.lbs.activity.dao.repository.ActivityRepository;
import com.tarena.lbs.activity.pojo.param.ActivityAddParam;
import com.tarena.lbs.activity.pojo.po.ActivityPO;
import com.tarena.lbs.activity.pojo.query.ActivityQuery;
import com.tarena.lbs.activity.pojo.vo.ActivityVO;
import com.tarena.lbs.activity.service.ActivityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Slf4j
@Service
public class ActivityServiceImpl implements ActivityService {
    @Autowired
    private ActivityRepository activityRepository;
    @Override
    public void insertActivity(ActivityAddParam param) {
        log.info("控制层-商家活动保存"+param);
        ActivityPO activity=new ActivityPO();
        BeanUtils.copyProperties(param,activity);
        activity.setCreateAt(new Date());
        activityRepository.insert(activity);
    }

    @Override
    public ActivityVO selectByActivityId(Integer id) {
        log.info("控制层-商家活动详情"+id);
        ActivityVO activity=activityRepository.selectByActivityId(id);
        return activity;
    }

    @Override
    public List<ActivityVO> selectList() {
        List<ActivityVO> list=activityRepository.selectList();
        return list;
    }

    @Override
    public void updateActivityStatus(Integer id, Integer status) {
        ActivityPO activity=new ActivityPO();
        activity.setId(id);
        activity.setStatus(status);
        activity.setUpdateAt(new Date());
        activityRepository.updateActivityStatus(activity);
    }

    @Override
    public void deleteActivity(Integer id) {
        activityRepository.delete(id);
    }

    @Override
    public List<ActivityVO> selectActivity(ActivityQuery query) {
        List<ActivityVO> list=activityRepository.selectActivity(query);
        return list;
    }
}
